import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';


main() => runApp(MyApp());

class BatteryPage extends StatefulWidget {
  @override
  _BatteryPage createState() {
    // TODO: implement createState
    return _BatteryPage();
  }

}

class _BatteryPage extends State<BatteryPage> {

  static const platform = const MethodChannel('samples.flutter.io/battery');

  String _batteryLevel = 'Unknown battery level.';

  Future<Null> _getBatteryLevel() async {
    String batteryLevel;
    try {
      final int result = await platform.invokeMethod('getBatteryLevel');
      batteryLevel = 'Battery level at $result % .';
    } on PlatformException catch (e) {
      batteryLevel = "Failed to get battery level: '${e.message}'.";
    }

    setState(() {
      _batteryLevel = batteryLevel;
    });
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Material(
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            RaisedButton(
              onPressed: _getBatteryLevel,
              child:  Text(_batteryLevel),
            )
          ],
        ),
      ),
    );
  }

}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: BatteryPage(),
    );
  }

}